home *** CD-ROM | disk | FTP | other *** search
/ Softwarová Záchrana 3 / Softwarova-zachrana-3.bin / PaperCut Quota / pc-setup.exe / {app} / WebAdmin / LogReport.asp < prev    next >
Text File  |  2005-02-04  |  23KB  |  653 lines

  1. <%@ Language=VBScript %>
  2. <%' (c) Copyright 1999-2004 PaperCut Software Pty. Ltd. %>
  3. <!-- #include file="includes/PCCommon.inc" -->
  4. <!--#include file="includes/header.inc" -->
  5.  
  6. <%
  7. If Request("ReportList") <> "" Then
  8.     ' Display the report list (nothing else)
  9.  
  10.     Sub OutputReportRow(strReportKey, strRowClass, strQueryString)
  11.         Dim strURL
  12.         Dim strReportName
  13.         strReportName = GetText(strReportKey)
  14.  
  15.         strURL = "LogReport.asp"
  16.         If strQueryString <> "" Then
  17.             strURL = strURL & "?cmdRun=Y&blnShowParams=N&txtTitle=" & Server.URLEncode(strReportName) & "&" & strQueryString
  18.         End If
  19.     %>
  20.         <TR class="<%=strRowClass%>">
  21.             <TD><A href="<%=strURL%>"><%=strReportName%></A></TD>
  22.             <TD><%= GetText(strReportKey & "Desc")%></TD>
  23.         </TR>
  24.     <%
  25.     End Sub
  26.  
  27. %>
  28.  
  29.     <H1><%= GetText("QuickReports")%></H1>
  30.     <h2><%= GetText("PrintReports")%></h2>
  31.     <TABLE class="webAdmin">
  32.         <TR>
  33.             <TH><%= GetText("ReportName")%></TH>
  34.             <TH><%= GetText("Description")%></TH>
  35.         </TR>
  36.         <%
  37.             OutputReportRow "TopPrintUsersJobs", "evenRow", "cboUsageType=PrintJobs&cboReportType=SummaryByUser&cboPeriod=PeriodMonth&cboSortBy=PrintJobs"
  38.             OutputReportRow "TopPrintUsersPages", "oddRow", "cboUsageType=PrintJobs&cboReportType=SummaryByUser&cboPeriod=PeriodMonth&cboSortBy=PagesPrinted"
  39.  
  40.             OutputReportRow "BusiestPrintersJobs", "evenRow", "cboUsageType=PrintJobs&cboReportType=SummaryByPrinter&cboPeriod=PeriodMonth&cboSortBy=PrintJobs"
  41.             OutputReportRow "BusiestPrintersPages", "oddRow", "cboUsageType=PrintJobs&cboReportType=SummaryByPrinter&cboPeriod=PeriodMonth&cboSortBy=PagesPrinted"
  42.  
  43.             OutputReportRow "PrintJobsExpensive", "evenRow", "cboUsageType=PrintJobs&cboReportType=Detailed&cboPeriod=PeriodMonth&cboSortBy=Cost"
  44.             OutputReportRow "PrintJobsBiggest", "oddRow", "cboUsageType=PrintJobs&cboReportType=Detailed&cboPeriod=PeriodMonth&cboSortBy=PagesPrinted"
  45.  
  46.             OutputReportRow "CancelledAndNotRefundedJobs", "evenRow", "cboUsageType=PrintJobs&cboReportType=Detailed&cboPeriod=PeriodMonth&cboPrintStatus=CancelledWithNoRefund"
  47.  
  48.             OutputReportRow "AdhocReports", "oddRow", ""
  49.         %>
  50.     </TABLE>
  51.  
  52.     <% If gblnHasNetCharging Then %>
  53.     <h2><%= GetText("NetReports")%></h2>
  54.     <TABLE class="webAdmin">
  55.         <TR>
  56.             <TH><%= GetText("ReportName")%></TH>
  57.             <TH><%= GetText("Description")%></TH>
  58.         </TR>
  59.         <%
  60.             OutputReportRow "TopNetUsersData", "evenRow", "cboUsageType=NetUsage&cboReportType=SummaryByUser&cboPeriod=PeriodMonth&cboSortBy=NetDataUsed"
  61.             OutputReportRow "TopNetUsersTime", "oddRow", "cboUsageType=NetUsage&cboReportType=SummaryByUser&cboPeriod=PeriodMonth&cboSortBy=NetTimeUsed"
  62.  
  63.             OutputReportRow "NetHighestDailyUseData", "evenRow", "cboUsageType=NetUsage&cboReportType=Detailed&cboPeriod=PeriodMonth&cboSortBy=NetDataUsed"
  64.             OutputReportRow "NetHighestDailyUseTime", "oddRow", "cboUsageType=NetUsage&cboReportType=Detailed&cboPeriod=PeriodMonth&cboSortBy=NetTimeUsed"
  65.  
  66.             OutputReportRow "AdhocReports", "evenRow", ""
  67.         %>
  68.     <% End If %>
  69.     </TABLE>
  70.  
  71.     <!--#include file="includes/footer.inc" -->
  72. <%
  73.     Response.End
  74. End If
  75. %>
  76.  
  77.  
  78. <SCRIPT language="JavaScript">
  79. <!--
  80.     var iRepTypeSummaryUser = 0;
  81.     var iRepTypeSummaryPrinter = 1;
  82.     var iRepTypeDetailed = 2;
  83.  
  84.  
  85.     function changeUsageType() {
  86.         try {
  87.             var usage = document.getElementById("cboUsageType");
  88.             var printer = document.getElementById("cboPrinter");
  89.             var status = document.getElementById("cboPrintStatus");
  90.             var doc = document.getElementById("txtDocument");
  91.             var report = document.getElementById("cboReportType");
  92.             //alert(usage.selectedIndex);
  93.  
  94.             if (usage.selectedIndex == 0) {
  95.                 printer.disabled = false;
  96.                 status.disabled = false;
  97.                 doc.disabled = false;
  98.                 report.options[iRepTypeSummaryPrinter].disabled = false;
  99.  
  100.             } else {
  101.                 printer.disabled = true;
  102.                 status.disabled = true;
  103.                 doc.disabled = true;
  104.                 report.options[iRepTypeSummaryPrinter].disabled = true;
  105.             }
  106.         } catch (e) {
  107.             // do not error
  108.         }
  109.         return true;
  110.     }
  111.  
  112.  
  113.     function showParams(bShow) {
  114.         var d = document.getElementById("divReportParams");
  115.  
  116.         if (bShow) {
  117.             d.style.display = "";
  118.  
  119.         } else {
  120.             d.style.display = "none";
  121.  
  122.         }
  123.     }
  124.  
  125.     function submitSearch() {
  126.         var reportForm = document.getElementById("frmReport");
  127.         reportForm.submit();
  128.     }
  129.  
  130.     function submitSearchForRecord(intRec) {
  131.         var reportForm = document.getElementById("frmReport");
  132.         var startRecord = document.getElementById("inpStartRecord");
  133.         startRecord.value = intRec;
  134.         reportForm.submit();
  135.     }
  136.  
  137.     function exportToExcel() {
  138.         var reportForm = document.getElementById("frmReport");
  139.         var r = document.getElementById("cmdRun");
  140.         r.value = "ExportToExcel"
  141.         reportForm.submit();
  142.     }
  143.  
  144.     function toggleShowParams() {
  145.         var d = document.getElementById("divReportParams")
  146.         var link = document.getElementById("reportParamLink")
  147.         var inpShowParams = document.getElementById("inpShowParams")
  148.         if (d.style.display == "none") {
  149.             d.style.display = "";
  150.             inpShowParams.value = "Y";
  151.             link.innerHTML = "<A href=\"javascript:toggleShowParams();\"><%=GetText("HideReportParameters")%></A>";
  152.         } else {
  153.             d.style.display = "none";
  154.             inpShowParams.value = "N";
  155.             link.innerHTML = "<A href=\"javascript:toggleShowParams();\"><%=GetText("ShowReportParameters")%></A>   <A href=\"javascript:exportToExcel();\"><%=GetText("RunReportExcel")%></A>";
  156.         }
  157.     }
  158.  
  159.     function init() {
  160.         changeUsageType();
  161.  
  162.         var inpShowParams = document.getElementById("inpShowParams")
  163.         if (inpShowParams.value == "N") {
  164.             toggleShowParams();
  165.         }
  166.     }
  167.  
  168. -->
  169. </SCRIPT>
  170.  
  171. <%
  172.     Dim intMaxRows
  173.     Dim strReportTitle
  174.     intMaxRows = 50000
  175.     strReportTitle = GetText("AdhocReports")
  176.  
  177.  
  178.     Dim strUsageType
  179.     Dim strReportType
  180.     Dim strSortByCol
  181.     Dim strPeriod
  182.     Dim strStatus
  183.     Dim strPrinter
  184.     Dim strDocument
  185.     Dim strUsername
  186.  
  187.     strUsageType = LCase(Trim(Request("cboUsageType")))
  188.     strReportType = LCase(Trim(Request("cboReportType")))
  189.     strSortByCol = LCase(Trim(Request("cboSortBy")))
  190.     strPeriod = Trim(Request("cboPeriod"))
  191.     strStatus = Trim(Request("cboPrintStatus"))
  192.     strPrinter = Trim(Request("cboPrinter"))
  193.     strDocument = Trim(Request("txtDocument"))
  194.     strUsername = Trim(Request("txtUsername"))
  195.     If strStatus = "" Then
  196.         strStatus = "Printed"
  197.     End If
  198.  
  199.  
  200.     If Trim(Request("txtTitle")) <> "" Then
  201.         strReportTitle = Trim(Request("txtTitle")) & " (" & GetText(strPeriod) & ")"
  202.     ElseIf Request("cmdRun") <> "" Then
  203.         strReportTitle = GetText(Trim(Request("cboUsageType"))) & " - " & GetText(Trim(Request("cboReportType"))) & " (" & GetText(strPeriod) & ")"
  204.     End If
  205.  
  206.     Sub DisplayPrinterSelect(sName, strSelected)
  207.         Dim objSettings
  208.         Dim arrPrinters
  209.         Set objSettings = Server.CreateObject("PCWebAdmin.PCSettings")
  210.         arrPrinters = objSettings.GetPrinters()
  211.  
  212.         Set objSettings = Nothing
  213.  
  214.         Response.Write "<SELECT name=""" & sName & """ id=""" & sName & """>" & vbCRLF
  215.         Response.Write vbTab & "<OPTION></OPTION>" & vbCRLF
  216.  
  217.         Dim i
  218.         For i = Lbound(arrPrinters) to UBound(arrPrinters)
  219.             If strSelected = arrPrinters(i) Then
  220.                 Response.Write vbTab & "<OPTION SELECTED>" & Server.HTMLEncode(arrPrinters(i)) & "</OPTION>" & vbCRLF
  221.             Else
  222.                 Response.Write vbTab & "<OPTION>" & Server.HTMLEncode(arrPrinters(i)) & "</OPTION>" & vbCRLF
  223.             End If
  224.         Next
  225.         Response.Write "</SELECT>" & vbCRLF
  226.     End Sub
  227.  
  228.  
  229.     Sub DisplaySelect(sName, arrItems, strSelected, blnIncludeBlank, strExtraHTML)
  230.         Response.Write "<SELECT name=""" & sName & """ id=""" & sName & """ " & strExtraHTML & ">" & vbCRLF
  231.         If blnIncludeBlank Then
  232.             Response.Write vbTab & "<OPTION></OPTION>" & vbCRLF
  233.         End If
  234.  
  235.         Dim i, s
  236.         For i = 0 to UBound(arrItems)
  237.             s = arrItems(i)
  238.             If strSelected = s Then
  239.                 Response.Write vbTab & "<OPTION value=""" & s & """ SELECTED>" & GetText(s) & "</OPTION>" & vbCRLF
  240.             Else
  241.                 Response.Write vbTab & "<OPTION value=""" & s & """>" & GetText(s) & "</OPTION>" & vbCRLF
  242.             End If
  243.         Next
  244.         Response.Write "</SELECT>" & vbCRLF
  245.     End Sub
  246.  
  247.     Sub DisplayTextbox(sName, sValue)
  248.         Response.write "<INPUT name=""" & sName & """ id=""" & sName & """ type=""text"" value=""" & Server.HTMLEncode(sValue) & """ />"
  249.     End Sub
  250.  
  251.     Function EscapeSQLString(s)
  252.         EscapeSQLString = Replace(s, "'", "''")
  253.     End Function
  254.  
  255.     Function IgnoreField(s)
  256.         If s = "ID" Then
  257.             IgnoreField = True
  258.         ElseIf s = "Refunded" Then
  259.             IgnoreField = True
  260.         ElseIf s = "Cancelled" Then
  261.             IgnoreField = True
  262.         ElseIf s = "Denied" Then
  263.             IgnoreField = True
  264.         Else
  265.             IgnoreField = False
  266.         End If
  267.     End Function
  268.  
  269.  
  270.     Sub DisplayRecordSet(strURL, objRS, lngStartRecord)
  271.         Dim lngRow
  272.         Dim lngField
  273.         Dim strAlign
  274.         Dim strValue
  275.         Dim vntValue
  276.  
  277.         If not objRS.EOF Then
  278.             objRS.MoveLast
  279.             objRS.MoveFirst
  280.         End If
  281.  
  282.         If not objRS.EOF and not objRS.BOF Then
  283.             objRS.MoveFirst
  284.         End If
  285.  
  286.         If Not objRS.EOF and lngStartRecord > 1 Then
  287.             objRS.MoveFirst
  288.             objRS.Move lngStartRecord-1
  289.         End If
  290.  
  291.         Response.Write "<TABLE width=""100%"" border=""0""><TR><TD align=""right"">"
  292.         DisplayPageNavigation "javascript:submitSearchForRecord(%intStartRecord%);", lngStartRecord, objRS.RecordCount
  293.         Response.Write "</TD></TR></TABLE>"
  294.  
  295.  
  296.         Response.Write "<TABLE width=""100%"" class=""webAdmin"">"
  297.         ' Header
  298.         Response.Write "<TR>"
  299.         For lngField = 0 to objRS.Fields.Count - 1
  300.             If Not IgnoreField(objRS(lngField).Name) Then
  301.                 Response.Write "<TH>" & GetText(objRS(lngField).Name) & "</TH>"
  302.             End If
  303.         Next
  304.         Response.Write "</TR>" & vbCRLF
  305.  
  306.         If objRS.RecordCount = 0 Then
  307.             Response.Write "<TR><TD colspan=""" & objRS.Fields.Count & """>"
  308.             Response.Write GetText("ResultsNoData")
  309.             Response.Write "</TD></TR>" & vbCRLF
  310.         End If
  311.  
  312.         lngRow = 0
  313.         Do While Not objRS.EOF and lngRow < mintRECORDS_PER_PAGE
  314.             Response.Write "<TR class=""" & RowClassHelper(lngRow) & """>"
  315.             For lngField = 0 to objRS.Fields.Count - 1
  316.                 if Not IgnoreField(objRS(lngField).Name) Then
  317.                     vntValue = objRS(lngField).Value
  318.                     Select Case objRS.Fields(lngField).Type
  319.                         Case 10
  320.                             ' Str
  321.                             strAlign = "left"
  322.                             strValue = vntValue
  323.                         Case 7
  324.                             ' Double
  325.                             strAlign = "right"
  326.                             If IsNull(vntValue) Then
  327.                                 vntValue = 0
  328.                             End If
  329.                             strValue = FormatNumber(vntValue, 2, true, false, true)
  330.  
  331.                         Case 4
  332.                             ' Long
  333.                             strAlign = "right"
  334.                             If IsNull(vntValue) Then
  335.                                 vntValue = 0
  336.                             End If
  337.                             strValue = FormatNumber(vntValue, 0, true, false, true)
  338.  
  339.                         Case 5
  340.                             ' Currency
  341.                             strAlign = "right"
  342.                             strValue = FormatCredit(vntValue)
  343.  
  344.                         Case 8
  345.                             ' Date
  346.                             strAlign = "left"
  347.                             strValue = FormatDateTime(vntValue)
  348.                         Case Else
  349.                             strAlign = "left"
  350.                             strValue = vntValue & " - " & objRS.Fields(lngField).Type
  351.                     End Select
  352.                     Response.Write "<TD align=""" & strAlign & """>"
  353.                     Dim bHasShown
  354.                     bHasShown = False
  355.                     If objRS.Fields(lngField).Name = "Status" Then
  356.                         'Special formatting for print log status field
  357.                         On Error Resume Next
  358.                         If objRS("UserName") <> "" And objRS("TotalCost") > 0 _
  359.                                 And objRS("ID") > 0 And Not objRS("Refunded") Then
  360.                             If Err.Number = 0 Then
  361.                                 DisplayPrintJobStatus strValue, objRS("UserName"), objRS("TotalCost"), objRS("ID"), False, objRS("Cancelled"), objRS("Denied")
  362.                                 bHasShown = True
  363.                             End If
  364.                             Err.Clear
  365.                         End If
  366.                         On Error Goto 0
  367.                     End If
  368.                     If Not bHasShown Then
  369.                         Response.Write strValue
  370.                     End If
  371.                     Response.Write "</TD>"
  372.                 End If
  373.             Next
  374.             Response.Write "</TR>" & vbCRLF
  375.  
  376.             lngRow = lngRow + 1
  377.             objRS.MoveNext
  378.         Loop
  379.  
  380.         Response.Write "</TABLE>"
  381.         Response.Write "<TABLE width=""100%"" border=""0""><TR><TD align=""right"">"
  382.         DisplayPageNavigation "javascript:submitSearchForRecord(%intStartRecord%);", lngStartRecord, objRS.RecordCount
  383.         Response.Write "</TD></TR></TABLE>"
  384.  
  385.     End Sub
  386.  
  387. %>
  388. <H1><% = strReportTitle %></H1>
  389.  
  390. <p>
  391.     <A href="LogReport.asp?ReportList=Y"><%= GetText("QuickReports") %></A>   <SPAN id="reportParamLink"><A href="javascript:toggleShowParams();"><%= GetText("HideReportParameters") %></A></SPAN>
  392. </p>
  393. <DIV id="divReportParams">
  394.     <FORM ACTION="LogReport.asp" METHOD="POST" ID="frmReport">
  395.       <INPUT id="cmdRun" name="cmdRun" type="hidden" value="Y">
  396.       <INPUT id="inpShowParams" name="blnShowParams" type="hidden" value="<%=Request("blnShowParams")%>">
  397.       <INPUT id="inpStartRecord" name="intStartRecord" type="hidden" value="">
  398.       <TABLE class="webAdmin" width="500">
  399.         <TR class="<%=RowClassHelper(1)%>" >
  400.           <TH width="30%"><%=GetText("UsageType")%>:</TH>
  401.           <TD width="70%"><% DisplaySelect "cboUsageType", Array("PrintJobs","NetUsage"), Request("cboUsageType"), False, " onchange=""changeUsageType();"" " %></TD>
  402.         </TR>
  403.         <TR class="<%=RowClassHelper(1)%>">
  404.           <TH><%=GetText("ReportType")%>:</Th>
  405.           <TD align="left"><% DisplaySelect "cboReportType", Array("SummaryByUser", "SummaryByPrinter", "Detailed"), Request("cboReportType"), False, "" %></TD>
  406.         </TR>
  407.         <TR class="<%=RowClassHelper(0)%>">
  408.           <TD colspan="2"><B><%=GetText("ReportFilters")%>:</B></TD>
  409.         </TR>
  410.         <TR class="<%=RowClassHelper(1)%>">
  411.           <TH><%=GetText("Period")%>:</Th>
  412.           <TD align="left"><% DisplaySelect "cboPeriod", Array("PeriodAll", "PeriodToday","PeriodWeek", "PeriodMonth", "Period3Months", "Period6Months"), Request("cboPeriod"), False, "" %></TD>
  413.         </TR>
  414.         <TR class="<%=RowClassHelper(1)%>">
  415.           <TH><%=GetText("Username")%>:</Th>
  416.           <TD align="left"><% DisplayTextbox "txtUsername", Request("txtUsername") %></TD>
  417.         </TR>
  418.         <TR class="<%=RowClassHelper(1)%>">
  419.           <TH><%=GetText("Printer")%>:</Th>
  420.           <TD align="left"><% DisplayPrinterSelect "cboPrinter", Request("cboPrinter") %></TD>
  421.         </TR>
  422.         <TR class="<%=RowClassHelper(1)%>">
  423.           <TH><%=GetText("PrintStatus")%>:</Th>
  424.           <TD align="left"><% DisplaySelect "cboPrintStatus", Array("Printed", "Denied", "Cancelled", "Refunded", "CancelledWithNoRefund", "AllDocuments"), Request("cboPrintStatus"), False, "" %></TD>
  425.         </TR>
  426.         <TR class="<%=RowClassHelper(1)%>">
  427.           <TH><%=GetText("Document")%>:</Th>
  428.           <TD align="left"><% DisplayTextbox "txtDocument", Request("txtDocument") %></TD>
  429.         </TR>
  430.         <TR class="<%=RowClassHelper(0)%>">
  431.           <TD colspan="2"><B><%=GetText("ReportSortOrder")%>:</B></TD>
  432.         </TR>
  433.         <TR class="<%=RowClassHelper(1)%>">
  434.           <TH><%=GetText("SortBy")%>:</Th>
  435.           <TD align="left"><% DisplaySelect "cboSortBy", Array("Time", "Username", "Printer", "PrintJobs", "PagesPrinted", "PagesPerJob", "Cost", "NetTimeUsed", "NetDataUsed"), Request("cboSortBy"), False, "" %></TD>
  436.         </TR>
  437.            <TR >
  438.           <TD colspan="2" align="right">
  439.               <INPUT type="submit" name="cmdRunButton" value="<%=GetText("RunReport")%>">
  440.               <INPUT type="button" onclick="exportToExcel();" value="<%=GetText("RunReportExcel")%>">
  441.           </TD>
  442.         </TR>
  443.       </TABLE>
  444.     </FORM>
  445. </DIV>
  446.  
  447. <%
  448. If Request("cmdRun") <> "" Then
  449.     Dim blnGroupByQuery
  450.     Dim strValidSorts
  451.     Dim strDateCol
  452.  
  453.     Dim strSQL
  454.     Dim strWhere
  455.     Dim strOrderBy
  456.  
  457.  
  458.     Dim strURL
  459.     strURL = "LogReport.asp?cboUsageType=" & Request("cboUsageType") & "&cboReportType=" & Request("cboReportType") & "&cboSortBy=" & Request("cboSortBy") & "&txtUsername=" & Request("txtUsername") & "&txtDocument=" & Request("txtDocument") & "&cboPrintStatus=" & Request("cboPrintStatus") & "&cboPrinter=" & Request("cboPrinter") & "&cboPeriod=" & Request("cboPeriod") & "&blnShowParams=" & Request("blnShowParams") & "&txtTitle=" & Request("txtTitle") & "&cmdRun=Go"
  460.  
  461.  
  462.     blnGroupByQuery = False
  463.     If strUsageType = "printjobs" Then
  464.         'Print Jobs
  465.         strDateCol = "[time]"
  466.         If strReportType = "detailed" Then
  467.             strSQL = "SELECT top " & intMaxRows & " [Time], Username, PrinterName as Printer, DocumentName as Document, pages as PagesPrinted, Cost as TotalCost, Status, ID, Refunded, Cancelled, Denied FROM JobLog WHERE 1 = 1 ##WHERE## ORDER BY ##ORDERBY## [time] desc, username asc"
  468.             strValidSorts = "time,username,printername,documentname,pages,cost,status"
  469.  
  470.         ElseIf strReportType = "summarybyuser" Then
  471.             strSQL = "SELECT top " & intMaxRows & " Username, CLng(SUM(pages)) as PagesPrinted, COUNT(*) as PrintJobs, AVG(pages) as PagesPerJob, SUM(cost) as TotalCost FROM JobLog WHERE 1 = 1 ##WHERE## GROUP BY username ORDER BY ##ORDERBY## username asc"
  472.             strValidSorts = "username,clng(sum(pages)),avg(pages),count(*),sum(cost)"
  473.             blnGroupByQuery = True
  474.  
  475.         ElseIf strReportType = "summarybyprinter" Then
  476.             strSQL = "SELECT top " & intMaxRows & " PrinterName, CLng(SUM(pages)) as PagesPrinted, COUNT(*) as PrintJobs, AVG(pages) as PagesPerJob, SUM(cost) as TotalCost FROM JobLog WHERE 1 = 1 ##WHERE## GROUP BY printername ORDER BY ##ORDERBY## printername asc"
  477.             strValidSorts = "printername,CLng(SUM(pages)),avg(pages),count(*),sum(cost)"
  478.             blnGroupByQuery = True
  479.  
  480.         End If
  481.     Else
  482.         'Net usage
  483.  
  484.         If Not gblnHasNetCharging Then
  485.             RedirectWithMessage "LogReport.asp", GetText("ReportsNoNetCharging")
  486.         End If
  487.  
  488.         strDateCol = "[logDate]"
  489.         If strReportType = "detailed" Then
  490.             strSQL = "SELECT top " & intMaxRows & " logdate as [Time], Username, totalmb as NetDataUsed, totalnethours as NetTimeUsed, Cost as TotalCost FROM NetChargeLog WHERE 1 = 1 ##WHERE## ORDER BY ##ORDERBY## logdate desc, username asc"
  491.             strValidSorts = "logdate,username,totalmb,totalnethours,cost"
  492.  
  493.             If strSortByCol = "time" Then
  494.                 strSortByCol = "logdate"
  495.             End If
  496.  
  497.         ElseIf strReportType = "summarybyuser" or strReportType = "summarybyprinter" Then
  498.             strSQL = "SELECT top " & intMaxRows & " Username, SUM(totalmb) as NetDataUsed, SUM(totalnethours) as NetTimeUsed, SUM(cost) as TotalCost FROM NetChargeLog WHERE 1 = 1 ##WHERE## GROUP BY username ORDER BY ##ORDERBY## username asc"
  499.             strValidSorts = "username,sum(totalmb),sum(totalnethours),sum(cost)"
  500.             blnGroupByQuery = True
  501.         End If
  502.  
  503.     End If
  504.  
  505.     If strUsername <> "" Then
  506.         strWhere = strWhere & " AND UserName LIKE '*" & EscapeSQLString(strUsername) & "*' "
  507.     End If
  508.  
  509.     If strUsageType = "printjobs" and strPrinter <> "" Then
  510.         strWhere = strWhere & " AND PrinterName = '" & EscapeSQLString(strPrinter) & "' "
  511.     End If
  512.  
  513.     If strUsageType = "printjobs" Then
  514.         If strStatus = "Cancelled" Then
  515.             strWhere = strWhere & " AND Cancelled = True "
  516.         ElseIf strStatus = "Refunded" Then
  517.             strWhere = strWhere & " AND Refunded = True "
  518.         ElseIf strStatus = "CancelledWithNoRefund" Then
  519.             strWhere = strWhere & " AND Cancelled = True AND Refunded = False "
  520.         ElseIf strStatus = "AllDocuments" Then
  521.             strWhere = strWhere & " "
  522.         Else
  523.             strWhere = strWhere & " AND Status LIKE '*" & strStatus &"*' "
  524.         End If
  525.     End If
  526.  
  527.     If strUsageType = "printjobs" and strDocument <> "" Then
  528.         strWhere = strWhere & " AND DocumentName LIKE '*" & EscapeSQLString(strDocument) & "*' "
  529.     End If
  530.  
  531.     If strPeriod <> "" Then
  532.         Dim dtmStartDate
  533.  
  534.         Select Case strPeriod
  535.             Case "PeriodToday"
  536.                 dtmStartDate = Date
  537.             Case "PeriodWeek"
  538.                 dtmStartDate = DateAdd("D", -7, Date)
  539.             Case "PeriodMonth"
  540.                 dtmStartDate = DateAdd("M", -1, Date)
  541.             Case "Period3Months"
  542.                 dtmStartDate = DateAdd("M", -3, Date)
  543.             Case "Period6Months"
  544.                 dtmStartDate = DateAdd("M", -6, Date)
  545.             Case "PeriodAll"
  546.                 ' no restriction
  547.         End Select
  548.  
  549.         If dtmStartDate <> 0 Then
  550.             strWhere = strWhere & " AND " & strDateCol & " >= " & CStr(CLng(dtmStartDate)) & " "
  551.         End If
  552.  
  553.     End If
  554.  
  555.     If strSortByCol <> "" Then
  556.         Dim strSortOrder
  557.  
  558.         Select Case strSortByCol
  559.             Case "username"
  560.                 strSortOrder = "ASC"
  561.             Case "printer"
  562.                 strSortOrder = "ASC"
  563.             Case Else
  564.                 strSortOrder = "DESC"
  565.         End Select
  566.  
  567.         If blnGroupByQuery Then
  568.             Select Case strSortByCol
  569.                 Case "cost"
  570.                     strSortByCol = "SUM(Cost)"
  571.                 Case "printjobs"
  572.                     strSortByCol = "COUNT(*)"
  573.                 Case "pagesprinted"
  574.                     strSortByCol = "clng(sum(pages))"
  575.                 Case "pagesperjob"
  576.                     strSortByCol = "avg(pages)"
  577.                 Case "days"
  578.                     strSortByCol = "COUNT(*)"
  579.                 Case "nettimeused"
  580.                     strSortByCol = "SUM(totalnethours)"
  581.                 Case "netdataused"
  582.                     strSortByCol = "SUM(totalmb)"
  583.                 Case "printer"
  584.                     strSortByCol = "printerName"
  585.             End Select
  586.         Else
  587.             Select Case strSortByCol
  588.                 Case "pagesprinted"
  589.                     strSortByCol = "pages"
  590.                 Case "nettimeused"
  591.                     strSortByCol = "totalnethours"
  592.                 Case "netdataused"
  593.                     strSortByCol = "totalmb"
  594.                 Case "printer"
  595.                     strSortByCol = "printerName"
  596.                 'Case Else
  597.                 '    strSortCol = "[" & strSortCol & "]"
  598.             End Select
  599.         End If
  600.  
  601.         'Response.write strValidSorts & "<BR>"
  602.         'Response.write strSortByCol & "<BR>"
  603.         If InStr(1, "," & strValidSorts & ",", "," & strSortByCol & ",", vbTextCompare) > 0 Then
  604.             strOrderBy = strOrderBy & strSortByCol & " " & strSortOrder & ", "
  605.         End if
  606.  
  607.     End If
  608.  
  609.  
  610.     strSQL = Replace(strSQL, "##WHERE##", strWhere)
  611.     strSQL = Replace(strSQL, "##ORDERBY##", strOrderBy)
  612.  
  613.     Response.Write "<!--" & strSQL & "-->"
  614.     'Response.End
  615.  
  616.     Dim objRS
  617.     Dim objReports
  618.     Set objReports = Server.CreateObject("PCWebAdmin.PCReports")
  619.     If strUsageType = "netusage" Then
  620.         Set objRS = objReports.QueryNetLog(strSQL)
  621.     Else
  622.         Set objRS = objReports.QueryPrintLog(strSQL)
  623.     End If
  624.     Set objReports = Nothing
  625.  
  626.     If Request("cmdRun") = "ExportToExcel" Then
  627.         ExportToExcel "UsageReport", objRS, True
  628.         Response.End
  629.     End If
  630.  
  631.     Dim intStartRecord
  632.     If Request("intStartRecord") = "" then
  633.         intStartRecord = 1
  634.     Else
  635.         intStartRecord = Int(Request("intStartRecord"))
  636.     End If
  637.  
  638.     DisplayRecordSet strURL, objRS, intStartRecord
  639.     objRS.Close
  640.     Set objRS = Nothing
  641. End If
  642. %>
  643.  
  644. <SCRIPT language="javascript">
  645. try {
  646.     init();
  647. } catch (e) {
  648.  
  649. }
  650. </SCRIPT>
  651.  
  652. <!--#include file="includes/footer.inc" -->
  653.